package service

// 请求响应类型定义

// CreateKnowledgeBaseRequest 创建知识库请求
type CreateKnowledgeBaseRequest struct {
	Name        string `json:"name" binding:"required"`
	Description string `json:"description"`
	Type        string `json:"type" binding:"required,oneof=document qa hybrid"`
	Config      string `json:"config"`
	CreatedBy   uint   `json:"created_by"`
}

// UpdateKnowledgeBaseRequest 更新知识库请求
type UpdateKnowledgeBaseRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Status      string `json:"status" binding:"omitempty,oneof=active inactive"`
	Config      string `json:"config"`
	UpdatedBy   uint   `json:"updated_by"`
}

// ListKnowledgeBasesRequest 获取知识库列表请求
type ListKnowledgeBasesRequest struct {
	Page     int    `form:"page" binding:"min=1"`
	PageSize int    `form:"page_size" binding:"min=1,max=100"`
	Type     string `form:"type"`
	Status   string `form:"status"`
}

// CreateDocumentRequest 创建文档请求
type CreateDocumentRequest struct {
	KnowledgeBaseID uint   `json:"knowledge_base_id" binding:"required"`
	Title           string `json:"title" binding:"required"`
	Content         string `json:"content" binding:"required"`
	ContentType     string `json:"content_type" binding:"required,oneof=text markdown html pdf"`
	Source          string `json:"source"`
	Language        string `json:"language"`
	Metadata        string `json:"metadata"`
	CreatedBy       uint   `json:"created_by"`
}

// UpdateDocumentRequest 更新文档请求
type UpdateDocumentRequest struct {
	Title       string `json:"title"`
	Content     string `json:"content"`
	ContentType string `json:"content_type" binding:"omitempty,oneof=text markdown html pdf"`
	Source      string `json:"source"`
	Metadata    string `json:"metadata"`
	UpdatedBy   uint   `json:"updated_by"`
}

// SearchRequest 搜索请求
type SearchRequest struct {
	KnowledgeBaseID uint                   `json:"knowledge_base_id" binding:"required"`
	Query           string                 `json:"query" binding:"required"`
	TopK            int                    `json:"top_k" binding:"min=1,max=100"`
	Threshold       float64                `json:"threshold" binding:"min=0,max=1"`
	Filters         map[string]interface{} `json:"filters"`
}

// SearchResponse 搜索响应
type SearchResponse struct {
	Results        []SearchResult `json:"results"`
	Total          int            `json:"total"`
	ProcessingTime int64          `json:"processing_time"` // 毫秒
}

// SearchResult 搜索结果
type SearchResult struct {
	ChunkID    uint                   `json:"chunk_id"`
	DocumentID uint                   `json:"document_id"`
	Title      string                 `json:"title"`
	Content    string                 `json:"content"`
	Score      float64                `json:"score"`
	Highlights []string               `json:"highlights"`
	Metadata   map[string]interface{} `json:"metadata"`
}

// QARequest 问答请求
type QARequest struct {
	KnowledgeBaseID uint    `json:"knowledge_base_id" binding:"required"`
	Question        string  `json:"question" binding:"required"`
	SessionID       string  `json:"session_id"`
	Context         string  `json:"context"`
	MaxTokens       int     `json:"max_tokens" binding:"min=1,max=4000"`
	Temperature     float64 `json:"temperature" binding:"min=0,max=2"`
}

// QAResponse 问答响应
type QAResponse struct {
	Answer         string         `json:"answer"`
	Sources        []SearchResult `json:"sources"`
	Confidence     float64        `json:"confidence"`
	TokenCount     int            `json:"token_count"`
	ProcessingTime int64          `json:"processing_time"`
	SessionID      string         `json:"session_id"`
}

// ChatRequest 对话请求
type ChatRequest struct {
	KnowledgeBaseID uint    `json:"knowledge_base_id" binding:"required"`
	Message         string  `json:"message" binding:"required"`
	SessionID       string  `json:"session_id" binding:"required"`
	MaxTokens       int     `json:"max_tokens" binding:"min=1,max=4000"`
	Temperature     float64 `json:"temperature" binding:"min=0,max=2"`
	Stream          bool    `json:"stream"`
}

// ChatResponse 对话响应
type ChatResponse struct {
	Message        string         `json:"message"`
	Sources        []SearchResult `json:"sources"`
	Confidence     float64        `json:"confidence"`
	TokenCount     int            `json:"token_count"`
	ProcessingTime int64          `json:"processing_time"`
	SessionID      string         `json:"session_id"`
	MessageID      uint           `json:"message_id"`
}

// EmbeddingRequest 向量化请求
type EmbeddingRequest struct {
	Text  string `json:"text" binding:"required"`
	Model string `json:"model"`
}

// EmbeddingResponse 向量化响应
type EmbeddingResponse struct {
	Vector    []float64 `json:"vector"`
	Dimension int       `json:"dimension"`
	Model     string    `json:"model"`
}

// BatchEmbeddingRequest 批量向量化请求
type BatchEmbeddingRequest struct {
	Texts []string `json:"texts" binding:"required"`
	Model string   `json:"model"`
}

// BatchEmbeddingResponse 批量向量化响应
type BatchEmbeddingResponse struct {
	Vectors   [][]float64 `json:"vectors"`
	Dimension int         `json:"dimension"`
	Model     string      `json:"model"`
	Count     int         `json:"count"`
}
